<template>
	<el-dialog :title="titleMap[mode]" v-model="visible" :width="400" destroy-on-close @closed="$emit('closed')">
		<el-form ref="dialogForm" :model="form" :rules="rules" label-width="100px" label-position="left">
			<el-form-item label="排序号">
				<el-input-number v-model="form.sortNo" placeholder="=排序号"></el-input-number>
			</el-form-item>
			<el-form-item label="模块标识" prop="code">
				<el-input v-model="form.code" placeholder="模块标识"></el-input>
			</el-form-item>
			<el-form-item label="模块名称" prop="name">
				<el-input v-model="form.name" placeholder="模块名称"></el-input>
			</el-form-item>
			<el-form-item label="站内消息">
				<el-radio v-model="form.webSms" label="0">禁用</el-radio>
				<el-radio v-model="form.webSms" label="1">可选</el-radio>
				<el-radio v-model="form.webSms" label="2">必选</el-radio>
			</el-form-item>
			<el-form-item label="外部邮件">
				<el-radio v-model="form.emailSms" label="0">禁用</el-radio>
				<el-radio v-model="form.emailSms" label="1">可选</el-radio>
				<el-radio v-model="form.emailSms" label="2">必选</el-radio>
			</el-form-item>
			<el-form-item label="手机短信">
				<el-radio v-model="form.mobileSms" label="0">禁用</el-radio>
				<el-radio v-model="form.mobileSms" label="1">可选</el-radio>
				<el-radio v-model="form.mobileSms" label="2">必选</el-radio>
			</el-form-item>
			<el-form-item label="微信消息">
				<el-radio v-model="form.wxSms" label="0">禁用</el-radio>
				<el-radio v-model="form.wxSms" label="1">可选</el-radio>
				<el-radio v-model="form.wxSms" label="2">必选</el-radio>
			</el-form-item>
			<el-form-item label="钉钉消息">
				<el-radio v-model="form.ddSms" label="0">禁用</el-radio>
				<el-radio v-model="form.ddSms" label="1">可选</el-radio>
				<el-radio v-model="form.ddSms" label="2">必选</el-radio>
			</el-form-item>
			<el-form-item label="APP消息">
				<el-radio v-model="form.appSms" label="0">禁用</el-radio>
				<el-radio v-model="form.appSms" label="1">可选</el-radio>
				<el-radio v-model="form.appSms" label="2">必选</el-radio>
			</el-form-item>
		</el-form>
		<template #footer>
			<el-button type="primary" :loading="isSaveing" @click="submit">保存</el-button>
			<el-button @click="visible=false">取消</el-button>
		</template>
	</el-dialog>
</template>

<script>
export default {
	emits: ['success', 'closed'],
	data() {
		return {
			loading: false,
			mode: "add",
			titleMap: {
				add: '新增',
				edit: '编辑'
			},
			form: {
				configId: "",
				sortNo: 0,
				code: '',
				name: '',
				webSms:'0',
				emailSms:'0',
				wxSms:'0',
				ddSms:'0',
				mobileSms:'0',
				appSms:'0'

			},
			visible: false,
			isSaveing: false,
			rules: {
				code: [
					{required: true, message: '模块标识不能为空', trigger: 'blur'}
				],
				name: [
					{required: true, message: '模块名称不能为空', trigger: 'blur'}
				]
			},
		}
	},
	mounted() {

	},
	methods: {
		//显示
		open(mode = 'add') {
			this.mode = mode;
			this.visible = true;
			return this;
		},
		//表单提交方法
		submit() {
			this.$refs.dialogForm.validate(async (valid) => {
				if (valid) {
					this.isSaveing = true;
					var res;
					if (this.mode == "add") {
						res = await this.$API.system.sysMsgConfig.insert.post(this.form);
					} else if (this.mode == "edit") {
						res = await this.$API.system.sysMsgConfig.update.post(this.form);
					}
					this.isSaveing = false;
					if (res.code == 200) {
						this.$emit('success')
						this.visible = false;
						this.$message.success("操作成功")
					} else {
						this.$alert(res.message, "提示", {type: 'error'})
					}
				}
			})
		},
		//表单注入数据
		setData(data) {
			this.form.configId = data.configId;
			this.form.sortNo = data.sortNo;
			this.form.code = data.code;
			this.form.name = data.name;
			this.form.webSms = data.webSms;
			this.form.emailSms = data.emailSms;
			this.form.mobileSms = data.mobileSms;
			this.form.ddSms = data.ddSms;
			this.form.wxSms = data.wxSms;
			this.form.appSms = data.appSms;
		}
	}
}
</script>

<style>
</style>
